<!-- #section:basics/content.breadcrumbs -->


<div class="breadcrumbs" id="breadcrumbs">
    <script type="text/javascript">
        try {
            ace.settings.check('breadcrumbs', 'fixed')
        } catch (e) {
        }
    </script>

    <ul class="breadcrumb">
        <li>
            <i class="ace-icon fa fa-home home-icon"></i>
            <a href="#">项目管理</a>
        </li>
        <li class="active">项目列表</li>
    </ul>

</div>

<!-- /section:basics/content.breadcrumbs -->
<div class="page-content">
    <form method="post" name="queryForm" action="./project/getProject" id="queryForm">
        <div class="page-header">
            <div class="row" style="vertical-align: middle">
                <div class="col-xs-4" id="nav-search">
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="input-group">
                                <input type="text" name="queryString" id="queryString" value="$!queryString"
                                       class="form-control search-query" placeholder="名称查询">
                                <span class="input-group-btn">
                                    <button type="button" onclick="doQuery(1)"
                                            class="btn btn-primary btn-sm">
                                        <span class="ace-icon fa fa-search icon-on-right bigger-110"></span>
                                        查询
                                    </button>
                                </span>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <a href="#modal-category" role="button" class="btn btn-sm btn-success"
                       onclick="load('./project/edit');" href="#modal-category" data-toggle="modal">
                        <i class="ace-icon fa fa-pencil-square-o bigger-120 "></i>添加项目
                    </a>
                </div>
            </div>
        </div>
        <!-- /.page-header -->

        <div class="row">
            <div class="col-xs-12">
                <table class="table table-striped table-bordered table-hover">
                    <thead>
                    <tr>
                        <th>ID</th>
                        <th>名称</th>
                        <th>浏览人数</th>
                        <th>喜欢人数</th>
                        <th>投票人数</th>
                        <th>开始时间</th>
                        <th>结束时间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody id="user_list"></tbody>
                </table>
            </div>
            <!-- /.span -->
        </div>
        <div id="biuuu_city" style="margin: 5px;text-align: center"></div>
    </form>
    <!-- /.row -->
</div>

<!--<script type="text/javascript" src="$request.contextPath/res/assets/js/ace/elements.fileinput.js"></script>-->

<script type="text/javascript">

    function showEditDialog(projectId) {
        validator.resetForm();
        $('#submitForm').clearForm();
        $('#submitForm').find('#projectId').val(projectId);
        $.ajax(
                {
                    type:"GET",
                    url:'./project/queryById',data:{projectId:projectId},
                    success:function(data) {
                        $.each(data,function(i,item){
                            if (i == 'imgUrl') {
                                $('#projectFile').ace_file_input('show_file_list', [{type: 'image', name: item}]);
                                $('#projectFile').parent().find('img').css({width: '150px', height: '150px'}).show();
                            } else {
                                $('#submitForm').find('#' + i).val(item);
                            }
                        });},
                    dataType:'JSON'});
        $('#modal-category').modal('show');
    }

    $(document).ready(function() {
        getPageData(1);
    });

    function doQuery() {
        getPageData(1);
    }

    function getPageData(curr){
        var brands;
        $.ajax({
            url: "./project/getProject",
            type: "POST",
            dataType: 'json',
            data: {
                "pgNum" : curr,
                "pgSize" : 12,
                "type" : 0,
                "query" : $("#queryString").val()
            },

            success: function (data) {
                brands = data["list"];
               // console.log(data.list);
                //调用分页
                laypage({
                    cont: 'biuuu_city',
                    pages: data['pages'],
                    curr: curr, //当前页
                    jump: function(obj, first){ //触发分页后的回调
                        if(!first){ //点击跳页触发函数自身，并传递当前页：obj.curr
                            getPageData(obj.curr);
                        }
                    }
                })

                var str = "";
                for(var i in brands){
                    var kys = brands[i];
                    str += "<tr>";
                    str += "<td>" + kys['projectId']+"</td>"
                    str += "<td>"
                            + "<a href=\"javascript:void(0)\"  onclick=\"load('./project/preview?projectId="+kys['projectId']+"')\"</a>"+kys['projectName']
                            + "<a style=\"float:right\" href=\"javascript:void(0)\"  onclick=\"load('./project/active?projectId="+kys['projectId'] +"')\"</a>"+'编辑进展）'
                            + "<a style=\"float:right\" href=\"javascript:void(0)\"  onclick=\"addToIndex("+kys['projectId']+")\"</a>"+'（加入首页精选|'
                            + "</td>";
                    str += "<td >" + kys['projectViewcnt'] + "</td>";
                    str += "<td >" + kys['projectLikecnt'] + "</td>";
                    str += "<td>" + kys['projectVotecnt'] + "</td>";
                    str += "<td >" +  kys['projectBegintime'] + "</td>";
                    str += "<td >" + kys['projectEndtime'] + "</td>";
                    str += "<td >"
                    str += "<div class=\"action-buttons\">"
                            +"<a class=\"green\" href=\"#\""
                            +"onclick=\"load('./project/edit?projectId="+kys['projectId'] +"')\""
                            +"title=\"编辑\""
                            +"hideFocus=\"true\">"
                            +"<i class=\"ace-icon fa fa-pencil bigger-130\" hideFocus=\"true\"></i>"
                            +"</a>";
                    str += "<a class=\"red\" href=\"javascrip:void(0)\" onclick=\"deleteProject("+kys['projectId']+")\""
                            +"title=\"删除\">"
                            +"<i class=\"ace-icon fa fa-trash-o bigger-130\"></i>"
                            +"</a>"
                            +"</div>";

                    str += "</td>";
                    str += "</tr>";
                }
                //console.log(str);
                $("#user_list").html(str);
            },
            error:function(data){
                layer.msg('获取记录失败！', {icon: 5});
            }
        });
    }

    function deleteProject(Id) {
        confirm('确认删除?', function () {
            $.ajax({
                type: "GET",
                url: './project/delete',
                data: {projectId: Id},
                success: function (data) {
                    if (data.resultCode == 0) {
                        succ('删除成功！');
                        getPageData(1);
                    } else {
                        error('删除失败！');
                    }
                },
                dataType: 'JSON'
            });
        });
    }

    function addToIndex(Id) {
        confirm('确认添加到主页精选?', function () {
            $.ajax({
                type: "GET",
                url: './project/AddToIndex',
                data: {projectId: Id},
                success: function (data) {
                    console.log(data);
                    if (data.resultCode == 0) {
                        succ('添加成功！');
                    } else {
                        error(data.resultMsg);
                    }
                },
                error:function(data) {
                    error("系统异常，请稍后再试!");
                },
                dataType: 'JSON'
            });
        });
    }
</script>